import time
#time
#查看时间
time.localtime()

#时间戳
time.time()

#时间格式转换
#time.struct_time->str
print(time.strftime("%Y-%m-%d %H:%M:%S"))

#str->time.struct_time
print(time.strptime("2020-11-09 14:40:50","%Y-%m-%d %H:%M:%S"))

#time.struct_time->tuple
print(tuple(time.localtime()))

#tuple-> time.struct_time
print(time.struct_time(tuple(time.localtime())))

#time.struct_time-> timestamp
print(time.localtime(time.time()))
print(time.gmtime(time.time()))

#time->time.struct_time
print(time.mktime(time.localtime()))

#datetime

from datetime import datetime
print(datetime.today())
print(datetime.now(tz=None))
print(datetime.utcnow())

#时间格式的转换
#datetime.datetime->str
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))

#str->datetime.datetime
now = datetime.now()
now_str = now.strftime("%Y-%m-%d %H:%M:%S")
print(datetime.strptime(now_str, "%Y-%m-%d %H:%M:%S"))

#datetime.datetime ->timetuple->tuple
now.timetuple()
print(tuple(now.timetuple()))

#tuple -> datetime.datetime
a = tuple(now.timetuple())
new_a = a[:-3]
print(datetime(*new_a))

#datetime.datetime -> timestamp
print(now.timestamp())

#timestamp -> datetime.datetime
print(datetime.fromtimestamp(now.timestamp()))

from datetime import timedelta
print(now + timedelta(hours=1))

#封装函数作业

def get_date(days):
    Day = datetime.today()
    result = (Day + timedelta(days=days)).strftime('%Y-%m-%d')
    return result

if __name__ == '__main__':

    print(get_date(2))















